package com.prp.struts.bean;

import java.util.Iterator;
import java.util.Set;

import com.prp.dao.Adminrole;
import com.prp.dao.Userinfo;
import com.prp.service.ServiceFactory;

public class UserAuth {
	private boolean is_Admin = false;
	private boolean is_FileAdmin = false;
	private boolean is_UserAdmin = false;
	private String username;
		
	
	public void setUsername(String username) {
		Set auths;
		this.username = username;
		auths = ServiceFactory.getUserAuthoritySys().getUserAuthority(username);
		Userinfo user= ServiceFactory.getUserManage().getUser(username);
		if (user != null)
			is_Admin = user.getIsAdmin();
		
		if (auths != null && is_Admin)
		{
			Iterator iter = auths.iterator();
			while(iter.hasNext()){
				Adminrole adminrole = (Adminrole) iter.next();
				int role = adminrole.getId().getRole().getRole();
				if (role == 1)
					is_UserAdmin = true;
				if (role == 2)
					is_FileAdmin = true;
				if (role == 3){
					is_FileAdmin = true;
					is_UserAdmin = true;
				}
			}
		}
	}
	public String getUsername() {
		return username;
	}

	
	public boolean isIs_Admin() {
		return is_Admin;
	}

	public boolean isIs_FileAdmin() {
		return is_FileAdmin;
	}

	public boolean isIs_UserAdmin() {
		return is_UserAdmin;
	}
}
